
#include "Shaders.h"

bool Shaders::init()
{
	if (!LearnShader::init())	return false;
	std::cout << getChapterName().c_str() << "::" << getNodeName().c_str() << "::init" << std::endl;

	m_pProgram = createProgramWithDefaultPath();

	CREATE_SHADER_VERTEX_DATA(pVertexData, Dataset_Vertices_Triangle_Color);
	pVertexData->setVertexSize(6);
	pVertexData->pushVertexAttrib(3, 0);
	pVertexData->pushVertexAttrib(3, 3);
	m_pVertex = ShaderBuffer::create(pVertexData);

	return true;
}

void Shaders::release()
{

}

void Shaders::update(float dt)
{
	glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	GLfloat timeValue = glfwGetTime();
	GLfloat greenValue = (sin(timeValue) / 2) + 0.5f;
	GLint vertexColorLocation = glGetUniformLocation(m_pProgram->getProgram(), "ourColor");
	m_pProgram->use();
	glUniform4f(vertexColorLocation, 0.0f, greenValue, 0.0f, 1.0f);

	m_pVertex->bindingVertexArray();
	m_pVertex->draw(3);
	m_pVertex->cleanVertexArray();
	
	swapBuffers();
}